
const mysql = require('mysql')

const pool = mysql.createPool({
    host:'localhost',
    port:3306,
    database:'biyuwu_information',
    user:'root',
    password:'yinghua'
})

exports.query=(sql,arr,callback_dao)=>{
    pool.getConnection((error,conn)=>{
        if(error){
            throw error;
            return;
        }

        conn.config.queryFormat = (query,values)=>{
            if(!values) return sql;
            else{
                return sql.replace(/\:(\w+)/g,(txt,key)=>{
                    if(values.hasOwnProperty(key)){
                        return values[key];
                    }
                    return txt;
                })
            }
        }
        conn.query(sql,arr,(error,results)=>{
            conn.release()
            if(error){
                throw error;
            }
            callback_dao(results)
        })
    })
}